<template>
	<view class="header-container">
		<!-- 头部搜索部分 -->
		<view class="header-search">
			<input class="header-search_input" type="text" value="" placeholder="商城宠粉节全场8折抢" />
			<text class="header-search_text">搜索</text>
		</view>
		<view class="header-content">

			<!-- 历史搜索 -->
			<view v-if="historyData.length" class="search-history margin-btm-20">
				<view class="search-title">
					<text>历史搜索</text>
					<text @click="clearHistory" class="iconfont icon-bangzhu right"></text>
				</view>
				<view class="search-history-content">
					<text v-for="item in historyData" class="search-history-content_text">{{item.name}}</text>
				</view>
			</view>
			<!-- 热门搜索 -->
			<view class="header-hot margin-btm-20">
				<view class="search-title">
					<text>热门搜索</text>
				</view>
				<view class="header-hot-content">
					<text v-for="(item,index) in hotData" class="search-history-content_text bgcolor-hot">{{item.name}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				historyData: [{
					id: 1,
					name: '西瓜'
				}, {
					id: 2,
					name: '香蕉'
				}, ],
				hotData:[
					{
						id:1,
						name:"苹果"
					},
					{
						id:2,
						name:'橘子'
					},
					{
						id:1,
						name:"苹果"
					},
					{
						id:2,
						name:'橘子'
					},{
						id:1,
						name:"苹果"
					},
					{
						id:2,
						name:'橘子'
					}
				]
			}
		},
		methods: {
			clearHistory() {
				this.historyData = []
			}
		}
	}
</script>

<style lang="scss">
	.header-container {
		display: flex;
		flex-direction: column;
		height: 100%;
	}

	.header-search {
		margin-bottom: 10px;
		width: 100%;
		height: 40px;
		background-color: #fff;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0 10px;
		box-sizing: border-box;

		.header-search_input {
			width: 86%;
			background-color: #ede9e9;
			padding-left: 10px;
			border-radius: 5px;
			height: 28px;
		}
	}

	.header-content {
		padding: 10px;
		flex: 1;
		background-color: #fff;
		padding-top: 0;

		.search-title {
			height: 32px;
			color: #6b6a6a;
			margin-top: 10px;
		}

		.margin-btm-20 {
			margin-bottom: 20px;
		}

		.search-history-content_text {
			padding: 2px 6px;
			border: 1px solid #ccc;
			border-radius: 4px;
			margin-right: 7px;
		}

		.bgcolor-hot {
			background-color: #eceaea;
		}
	}
</style>
